package view;

import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SpringLayout;

import model.Kunde;

public class ModifyCustomerView extends Component
{
	private Container cont;
	private ArrayList<Kunde> list;
	private ArrayList<JButton> btnlist;

	private JLabel headline;

	public ModifyCustomerView(Container cont, ArrayList<Kunde> list)
	{
		super();
		this.cont = cont;
		this.list = list;
		this.initModifyCustomerView();
	}

	public void initModifyCustomerView()
	{
		SpringLayout layout = new SpringLayout();
		this.cont.setLayout(layout);
		this.cont.setSize(700, 400);
		
		this.headline = new JLabel("List of Customers");
		this.cont.add(headline);
		Iterator<Kunde> itr = list.iterator();
		int i = 0;
		int j = 0;
		btnlist = new ArrayList<JButton>();
		layout.putConstraint(SpringLayout.WEST, headline, 5, SpringLayout.WEST, cont);
		layout.putConstraint(SpringLayout.NORTH, headline, 5, SpringLayout.NORTH,cont);
		while(itr.hasNext()){
			
		    Kunde tmp = itr.next();
		    JLabel lbl1 = new JLabel(tmp.getVorname());
		    JLabel lbl2 =new JLabel(tmp.getNachname());
			JButton btntmp = new JButton();
			btntmp.setName("edit"+i);
			btntmp.setText("Edit");
			this.cont.add(lbl1);
			this.cont.add(lbl2);
			this.cont.add(btntmp);
			layout.putConstraint(SpringLayout.WEST, lbl1, 5, SpringLayout.WEST, cont);
			layout.putConstraint(SpringLayout.NORTH, lbl1, 30+j, SpringLayout.NORTH,cont);
			layout.putConstraint(SpringLayout.WEST, lbl2, 5, SpringLayout.EAST, lbl1);
			layout.putConstraint(SpringLayout.NORTH, lbl2, 30+j, SpringLayout.NORTH,cont);
			layout.putConstraint(SpringLayout.WEST, btntmp, 5, SpringLayout.EAST, lbl2);
			layout.putConstraint(SpringLayout.NORTH, btntmp, 30+j, SpringLayout.NORTH,cont);
			this.btnlist.add(btntmp);
			i++;
			j = j+25;
		}

	}
	public void addActionsListeners(ActionListener a1){
		Iterator itr = btnlist.iterator();
		while(itr.hasNext()){
			JButton tmp = (JButton)itr.next();
			tmp.addActionListener(a1);
		}
	}

	public ArrayList<JButton> getBtnlist()
	{
		return btnlist;
	}

	public void setBtnlist(ArrayList<JButton> btnlist)
	{
		this.btnlist = btnlist;
	}
	

}
